<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Function Basics (GNU Compiler Collection (GCC) Internals)</title>

<meta name="description" content="Function Basics (GNU Compiler Collection (GCC) Internals)">
<meta name="keywords" content="Function Basics (GNU Compiler Collection (GCC) Internals)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Option-Index.html" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Functions.html" rel="up" title="Functions">
<link href="Function-Properties.html" rel="next" title="Function Properties">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
-->
</style>


</head>

<body lang="en">
<div class="subsection-level-extent" id="Function-Basics">
<div class="nav-panel">
<p>
Next: <a href="Function-Properties.html" accesskey="n" rel="next">Function Properties</a>, Up: <a href="Functions.html" accesskey="u" rel="up">Functions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h4 class="subsection" id="Function-Basics-1"><span>11.8.1 Function Basics<a class="copiable-link" href="#Function-Basics-1"> &para;</a></span></h4>
<a class="index-entry-id" id="index-DECL_005fNAME-1"></a>
<a class="index-entry-id" id="index-DECL_005fASSEMBLER_005fNAME"></a>
<a class="index-entry-id" id="index-TREE_005fPUBLIC"></a>
<a class="index-entry-id" id="index-DECL_005fARTIFICIAL-1"></a>
<a class="index-entry-id" id="index-DECL_005fFUNCTION_005fSPECIFIC_005fTARGET"></a>
<a class="index-entry-id" id="index-DECL_005fFUNCTION_005fSPECIFIC_005fOPTIMIZATION"></a>

<p>A function has four core parts: the name, the parameters, the result,
and the body.  The following macros and functions access these parts
of a <code class="code">FUNCTION_DECL</code> as well as other basic features:
</p><dl class="ftable">
<dt><a id="index-DECL_005fNAME-2"></a><span><code class="code">DECL_NAME</code><a class="copiable-link" href="#index-DECL_005fNAME-2"> &para;</a></span></dt>
<dd><p>This macro returns the unqualified name of the function, as an
<code class="code">IDENTIFIER_NODE</code>.  For an instantiation of a function template,
the <code class="code">DECL_NAME</code> is the unqualified name of the template, not
something like <code class="code">f&lt;int&gt;</code>.  The value of <code class="code">DECL_NAME</code> is
undefined when used on a constructor, destructor, overloaded operator,
or type-conversion operator, or any function that is implicitly
generated by the compiler.  See below for macros that can be used to
distinguish these cases.
</p>
</dd>
<dt><a id="index-DECL_005fASSEMBLER_005fNAME-1"></a><span><code class="code">DECL_ASSEMBLER_NAME</code><a class="copiable-link" href="#index-DECL_005fASSEMBLER_005fNAME-1"> &para;</a></span></dt>
<dd><p>This macro returns the mangled name of the function, also an
<code class="code">IDENTIFIER_NODE</code>.  This name does not contain leading underscores
on systems that prefix all identifiers with underscores.  The mangled
name is computed in the same way on all platforms; if special processing
is required to deal with the object file format used on a particular
platform, it is the responsibility of the back end to perform those
modifications.  (Of course, the back end should not modify
<code class="code">DECL_ASSEMBLER_NAME</code> itself.)
</p>
<p>Using <code class="code">DECL_ASSEMBLER_NAME</code> will cause additional memory to be
allocated (for the mangled name of the entity) so it should be used
only when emitting assembly code.  It should not be used within the
optimizers to determine whether or not two declarations are the same,
even though some of the existing optimizers do use it in that way.
These uses will be removed over time.
</p>
</dd>
<dt><a id="index-DECL_005fARGUMENTS"></a><span><code class="code">DECL_ARGUMENTS</code><a class="copiable-link" href="#index-DECL_005fARGUMENTS"> &para;</a></span></dt>
<dd><p>This macro returns the <code class="code">PARM_DECL</code> for the first argument to the
function.  Subsequent <code class="code">PARM_DECL</code> nodes can be obtained by
following the <code class="code">TREE_CHAIN</code> links.
</p>
</dd>
<dt><a id="index-DECL_005fRESULT"></a><span><code class="code">DECL_RESULT</code><a class="copiable-link" href="#index-DECL_005fRESULT"> &para;</a></span></dt>
<dd><p>This macro returns the <code class="code">RESULT_DECL</code> for the function.
</p>
</dd>
<dt><a id="index-DECL_005fSAVED_005fTREE"></a><span><code class="code">DECL_SAVED_TREE</code><a class="copiable-link" href="#index-DECL_005fSAVED_005fTREE"> &para;</a></span></dt>
<dd><p>This macro returns the complete body of the function.
</p>
</dd>
<dt><a id="index-TREE_005fTYPE-5"></a><span><code class="code">TREE_TYPE</code><a class="copiable-link" href="#index-TREE_005fTYPE-5"> &para;</a></span></dt>
<dd><p>This macro returns the <code class="code">FUNCTION_TYPE</code> or <code class="code">METHOD_TYPE</code> for
the function.
</p>
</dd>
<dt><a id="index-DECL_005fINITIAL-1"></a><span><code class="code">DECL_INITIAL</code><a class="copiable-link" href="#index-DECL_005fINITIAL-1"> &para;</a></span></dt>
<dd><p>A function that has a definition in the current translation unit will
have a non-<code class="code">NULL</code> <code class="code">DECL_INITIAL</code>.  However, back ends should not make
use of the particular value given by <code class="code">DECL_INITIAL</code>.
</p>
<p>It should contain a tree of <code class="code">BLOCK</code> nodes that mirrors the scopes
that variables are bound in the function.  Each block contains a list
of decls declared in a basic block, a pointer to a chain of blocks at
the next lower scope level, then a pointer to the next block at the
same level and a backpointer to the parent <code class="code">BLOCK</code> or
<code class="code">FUNCTION_DECL</code>.  So given a function as follows:
</p>
<div class="example smallexample">
<pre class="example-preformatted">void foo()
{
  int a;
  {
    int b;
  }
  int c;
}
</pre></div>

<p>you would get the following:
</p>
<div class="example smallexample">
<pre class="example-preformatted">tree foo = FUNCTION_DECL;
tree decl_a = VAR_DECL;
tree decl_b = VAR_DECL;
tree decl_c = VAR_DECL;
tree block_a = BLOCK;
tree block_b = BLOCK;
tree block_c = BLOCK;
BLOCK_VARS(block_a) = decl_a;
BLOCK_SUBBLOCKS(block_a) = block_b;
BLOCK_CHAIN(block_a) = block_c;
BLOCK_SUPERCONTEXT(block_a) = foo;
BLOCK_VARS(block_b) = decl_b;
BLOCK_SUPERCONTEXT(block_b) = block_a;
BLOCK_VARS(block_c) = decl_c;
BLOCK_SUPERCONTEXT(block_c) = foo;
DECL_INITIAL(foo) = block_a;
</pre></div>

</dd>
</dl>


</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Function-Properties.html">Function Properties</a>, Up: <a href="Functions.html">Functions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
